<template>
    <div>
        <h1>权益显示</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>权益编号</td>
                    <td>权益名称</td>
                    <td>权益状态</td>
                    <td>是否删除</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in date">
                    <td>{{ a.rightLevelId }}</td>
                    <td>{{ a.rightLevelName }}</td>
                    <td>{{ a.rstate?"启用":"禁用" }}</td>
                    <td>{{ a.isDelete }}</td>
                    <td>
                        <input type="button" :value="a.rstate?'禁用':'启用'" @click="zhuang(a.rightLevelId)">
                        <input type="button" value="修改" @click="xiu(a.rightLevelId)">
                        <input type="button" value="删除" @click="Del(a.rightLevelId)">
                    </td>
                </tr>
            </tbody>
        </table>
        <a href="/AddRight">新增权益</a>
    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';
const routher = useRouter()
onMounted(()=>{
    show()
})
const Del=(val:any)=>{
    if(!confirm("确认删除吗")){
        return
    }
    axios.delete("https://localhost:7258/api/RightLevel/Disdelete",{params:{id:val}}).then(res=>{
        if(res.data>0){
            alert("删除成功")
            show()
        }
        else{
            alert("删除失败")
        }
    })
}
const xiu=(val:any)=>{
    routher.push({path:"/UpdRight",query:{id:val}})
}
const zhuang=(val:any)=>{
    if(!confirm("确认修改状态吗")){
        return
    }
    axios.get("https://localhost:7258/api/RightLevel/Rstate",{params:{id:val}}).then(res=>{
        if(res.data>0){
            alert("修改状态成功")
            show();
        }
        else{
            alert("修改状态失败")
        }
    })
}
const show=()=>{
    axios.get("https://localhost:7258/api/RightLevel/GetRightLevels",{params:date.value}).then(res=>{
        date.value=res.data
    })
}
const date=ref([{
  "rightLevelId": 0,
  "rightLevelName": "",
  "rstate": false,
  "isDelete": false
}])
</script>

<style scoped>

</style>